package com.asa;

import com.asa.tongji.BaseFunction;
import com.asa.tongji.TUtils1;
import com.asa.utils.Calculate;

public class TClient {

	public static void main(String[] args) {
		
//		one();
		two();
//		threeone();
		
//		threetwo();
//		test1();
		
		
		
		
		
	}

	private static void test1() {
		final double u = 5;
		int n = 20;
		final double o = (double)u*n/(double)12;//均匀分布计算方差，范围除以12
		
		double v = 105;
		double p = (v - n*u)/(Math.sqrt(o*20));
		
//		double gailvdegailv = TUtils.gailvdegailv(1920, 16*100, 16*16*100/12);
		double gailvdegailv = TUtils1.gailvdegailv(105, 20*5, o*20);

		//System.out.println(1-gailvdegailv);
	}

	private static void threetwo() {
		HanShu hanShu = new HanShu() {
			
			@Override
			public double hanshu(double t, double x) {
				// TODO Auto-generated method stub
				return 0;
			}
			
			@Override
			public double hanshu(double x0) {
				// TODO Auto-generated method stub
				return BaseFunction.normaldistribution(x0, 0, 1);
			}
		};
		
		
		
		double p = (340 - 400*0.8)/(Math.sqrt(400*0.8*0.2));
		double hanshujifen1 = Calculate.hanshujifen(-10, p, hanShu);
		//System.out.println(hanshujifen1);
	}

	private static void threeone() {
		double [] g = {0.05,0.8,0.15};
		double[] a = {0,1,2};
		double va = TUtils1.variance3(g, a);
		double av = TUtils1.average2(g, a);
		double v = 450;
		double asa = 400;
		double xav = asa*av;
		
		
		double p = (v - asa*av)/(Math.sqrt(400*va));
		//System.out.println(p);
		
		HanShu hanShu = new HanShu() {
			
			@Override
			public double hanshu(double t, double x) {
				// TODO Auto-generated method stub
				return 0;
			}
			
			@Override
			public double hanshu(double x0) {
				// TODO Auto-generated method stub
				return BaseFunction.normaldistribution(x0, 0, 1);
			}
		};
		
		double hanshujifen1 = Calculate.hanshujifen(-10, p, hanShu);
		
		//System.out.println(1-hanshujifen1);
	}
	
	/**
	 * 例2-M舶在某海区航行，已知每遭受一次波浪的冲击，纵拐角大于3。的概率为p-1/3，若船舶遭受了90 000次波浪冲击，问其中有29 500～30 500次纵多角度大于3。的概率是多少?解我们将船舶每遭受一次波浪冲击看作是一次试验，并假定各次试验是独立的，在90 000次波浪冲击中纵摇角度大于3。的次数记为X,则X是一个随机变量，且有X～b(90 000,1/3)，其分布律为所求的概率为p{29 5oo x. 3o 5oo}-, X(9o 0o) ($)'()'"W"§2中心极限定理125要直接计算是麻烦的，我们利用棣莫弗一拉普拉斯定理来求它的近似值.即有P{29 5004X430 500}苴Fb =q门门门门南至·l/R目0省
	 */
	private static void two() {
		int all = 90000;
		int a = 29500;
		int b = 30500;
		double p = (double)1/(double)3;
		
		double v1 = (a - all*p)/(Math.sqrt(all*p*(1-p)));
		
		double v2 = (b - all*p)/(Math.sqrt(all*p*(1-p)));
		HanShu hanShu = new HanShu() {
			
			@Override
			public double hanshu(double t, double x) {
				// TODO Auto-generated method stub
				return 0;
			}
			
			@Override
			public double hanshu(double x0) {
				// TODO Auto-generated method stub
				return BaseFunction.normaldistribution(x0, 0, 1);
			}
		};
		
		//System.out.println(v1);
		//System.out.println(v2);
		double hanshujifen1 = Calculate.hanshujifen(-10, v1, hanShu);
		double hanshujifen21 = Calculate.hanshujifen(-10, 0, hanShu);
		double hanshujifen22 = Calculate.hanshujifen(0, v2, hanShu);
		//System.out.println(hanshujifen21+"==============================="+hanshujifen22+"               "+hanshujifen1);
		//System.out.println((hanshujifen22 +hanshujifen21)-hanshujifen1);
	}
	/**
	 * .例1一加法器同时收到20个噪声电压V,(k一1,2，'"，20)，设它们是相20互独立的随机变量，且都在区间(0,10)上服从均匀分布，记V一亘二V,，求医一飞P{V〉105}的近似值
	 * page 124
	 */
	private static void one() {
		final double u = 5;
		final double o = (double)100/(double)12;//均匀分布计算方差，范围除以12
		int n = 20;
		double v = 105;
		double p = (v - n*u)/(Math.sqrt(o*20));
		//System.out.println(p);
		
		HanShu hanShu = new HanShu() {
			
			@Override
			public double hanshu(double t, double x) {
				// TODO Auto-generated method stub
				return 0;
			}
			
			@Override
			public double hanshu(double x0) {
				// TODO Auto-generated method stub
				return BaseFunction.normaldistribution(x0, 0, 1);
			}
		};
		double hanshujifen1 = Calculate.hanshujifen(-10, 0, hanShu);
		double hanshujifen2 = Calculate.hanshujifen(0, p, hanShu);
		//System.out.println(1-(hanshujifen1 +hanshujifen2));
	}
	
	
	
}
